$OpenBSD: patch-src_gvcore_pngformattype_cpp,v 1.1 2011/07/08 20:36:09 naddy Exp $

Fix build with png-1.5.

--- src/gvcore/pngformattype.cpp.orig	Sat Sep 15 07:46:13 2007
+++ src/gvcore/pngformattype.cpp	Tue Jul  5 23:17:11 2011
@@ -211,7 +211,7 @@ void setup_qt( QImage& image, png_structp png_ptr, png
 
     if ( color_type == PNG_COLOR_TYPE_GRAY ) {
 	// Black & White or 8-bit grayscale
-	if ( bit_depth == 1 && info_ptr->channels == 1 ) {
+	if ( bit_depth == 1 && png_get_channels(png_ptr, info_ptr) == 1 ) {
 	    png_set_invert_mono( png_ptr );
 	    png_read_update_info( png_ptr, info_ptr );
 	    if (!image.create( width, height, 1, 2, QImage::BigEndian ))
@@ -245,16 +245,24 @@ void setup_qt( QImage& image, png_structp png_ptr, png
 		image.setColor( i, qRgba(c,c,c,0xff) );
 	    }
 	    if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) {
-		const int g = info_ptr->trans_values.gray;
+		png_bytep trans_alpha;
+		int num_trans;
+		png_color_16p trans_color;
+		png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color);
+		const int g = trans_color->gray;
 		if (g < ncols) {
 		    image.setAlphaBuffer(TRUE);
 		    image.setColor(g, image.color(g) & RGB_MASK);
 		}
 	    }
 	}
-    } else if ( color_type == PNG_COLOR_TYPE_PALETTE
+    } else {
+     png_colorp palette;
+     int num_palette;
+     png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
+     if ( color_type == PNG_COLOR_TYPE_PALETTE
      && png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)
-     && info_ptr->num_palette <= 256 )
+     && num_palette <= 256 )
     {
 	// 1-bit and 8-bit color
 	if ( bit_depth != 1 )
@@ -262,28 +270,32 @@ void setup_qt( QImage& image, png_structp png_ptr, png
 	png_read_update_info( png_ptr, info_ptr );
 	png_get_IHDR(png_ptr, info_ptr,
 	    &width, &height, &bit_depth, &color_type, 0, 0, 0);
-	if (!image.create(width, height, bit_depth, info_ptr->num_palette,
+	if (!image.create(width, height, bit_depth, num_palette,
 	    QImage::BigEndian))
 	    return;
 	int i = 0;
 	if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) {
+	    png_bytep trans_alpha;
+	    int num_trans;
+	    png_color_16p trans_color;
+	    png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color);
 	    image.setAlphaBuffer( TRUE );
-	    while ( i < info_ptr->num_trans ) {
+	    while ( i < num_trans ) {
 		image.setColor(i, qRgba(
-		    info_ptr->palette[i].red,
-		    info_ptr->palette[i].green,
-		    info_ptr->palette[i].blue,
-		    info_ptr->trans[i]
+		    palette[i].red,
+		    palette[i].green,
+		    palette[i].blue,
+		    trans_alpha[i]
 		    )
 		);
 		i++;
 	    }
 	}
-	while ( i < info_ptr->num_palette ) {
+	while ( i < num_palette ) {
 	    image.setColor(i, qRgba(
-		info_ptr->palette[i].red,
-		info_ptr->palette[i].green,
-		info_ptr->palette[i].blue,
+		palette[i].red,
+		palette[i].green,
+		palette[i].blue,
 		0xff
 		)
 	    );
@@ -318,12 +330,13 @@ void setup_qt( QImage& image, png_structp png_ptr, png
 	}
 
 	png_read_update_info(png_ptr, info_ptr);
-    }
+      }
 
     // Qt==ARGB==Big(ARGB)==Little(BGRA)
     if ( QImage::systemByteOrder() == QImage::LittleEndian ) {
 	png_set_bgr(png_ptr);
     }
+    }
 }
 
 
@@ -381,7 +394,7 @@ int PNGFormat::decode(QImage& img, QImageConsumer* con
 	    return -1;
 	}
 
-	if (setjmp((png_ptr)->jmpbuf)) {
+	if (setjmp(png_jmpbuf(png_ptr))) {
 	    png_destroy_read_struct(&png_ptr, &info_ptr, 0);
 	    image = 0;
 	    return -1;
@@ -409,7 +422,7 @@ int PNGFormat::decode(QImage& img, QImageConsumer* con
 
     if ( !png_ptr ) return 0;
 
-    if (setjmp(png_ptr->jmpbuf)) {
+    if (setjmp(png_jmpbuf(png_ptr))) {
 	png_destroy_read_struct(&png_ptr, &info_ptr, 0);
 	image = 0;
 	state = MovieStart;
@@ -476,7 +489,7 @@ void PNGFormat::end(png_structp png, png_infop info)
     consumer->frameDone(QPoint(offx,offy),r);
     consumer->end();
     state = FrameStart;
-    unused_data = (int)png->buffer_size; // Since libpng doesn't tell us
+    unused_data = png_process_data_pause(png, 1);
 }
 
 #ifdef PNG_USER_CHUNKS_SUPPORTED
